function cutLoginType(formId, form){
    $("div.login_box_type a").removeClass("active");
    $(form).addClass("active");
    $("div.login_box form").hide();
    $("#"+formId).show();
}
//登入函数
function init_login(is_focus_username,doc_username_id,doc_pwd_id,
        submit_id,form_id,post_url,redirect_url,finger_login_id
    ){
    var $user_name=$("#"+doc_username_id);
    var $user_pwd=$("#"+doc_pwd_id);
    var $login = $("#"+submit_id);
    var $login_form = $("#"+form_id);
    var $finger_login = $("#"+finger_login_id);
    //焦点
    if(is_focus_username){
		$user_name.focus();
    }
    $user_pwd.keypress(function(event){
        if(event.keyCode==13){
            $login.click();
        }
    });

    //password login
    $login.click(function(){
        $(".error_tip").html('&nbsp;');
        if($.trim($user_name.val())=="" || $.trim($user_pwd.val())==""){
            error_tip($("#id_corrent_up_info").val());
            $user_name.select();
            return false;
        }
        $("#id_login_type").val('pwd');
        var serialize_form = $login_form.serialize();
        $.ajax({
            url:post_url,
            type:"POST",
            data:serialize_form,
            dataType:"html",
            success:function(msg){
                if(msg=='ok'){
                    var index=window.location.href.indexOf("?next=");
                    var self_index = window.location.href.indexOf("selfservice");
                    if(index!=-1 && is_focus_username && self_index==-1){
                        window.location.href=window.location.href.substring(index+6);
                    }else{
                        window.location.href=redirect_url;
                    }
                }else{
                    $user_name.select();
                    $user_pwd.val('');
                    $user_pwd.blur();
                    error_tip(msg);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
               // alert(textStatus+" "+errorThrown);
            }
        });
    });

    //finger login
    $finger_login.click(function() {
        if(!canConnection){
            alert(gettext('请安装指纹驱动或启动该服务!'));
            return false;
        }
        $(".error_tip").html('&nbsp;');
        $("#id_pwdlogin").attr("disabled", true);
        $("#id_login_type").val('fp');
        $user_name.val("");
        $user_pwd.val("");
        $user_name.blur()
        $user_pwd.blur()
        //$user_name.select();
        fpLoginInit();
    });

}
function error_tip(msg){
    var tip = '<img src="/media/images/abroad_att/tip.png" style="margin-right: 4px;margin-top: -3px"/>'+msg;
    $(".error_tip").html(tip);
}
$(function(){
    if(document.body.offsetWidth < 900 || document.body.offsetHeight < 360){
        top.moveTo(0,0);
        top.resizeTo(screen.availWidth,screen.availHeight);
    }
    //输入框切换
    $(".login_inp_tip").focus(function(){
        if($(this).attr('id') == 'id_usernameTip'){
            $(this).hide();
            $("#id_username").show();
            $("#id_username").focus();
        }
        else if($(this).attr('id') == 'id_passwordTip'){
            $(this).hide();
            $("#id_password").show();
            $("#id_password").focus();   
        }
        else if($(this).attr('id') == 'id_empNameTip'){
            $(this).hide();
            $("#id_empName").show();
            $("#id_empName").focus();
        }
        else if($(this).attr('id') == 'id_empPwdTip'){
            $(this).hide();
            $("#id_empPwd").show();
            $("#id_empPwd").focus();
        }
    });
    $(".login_inp").blur(function(){
        if($(this).attr('id') == 'id_username' && $(this).val() == ""){
            $(this).hide();
            $("#id_usernameTip").show();
        }
        else if($(this).attr('id') == 'id_password' && $(this).val() == ""){
            $(this).hide();
            $("#id_passwordTip").show();
        }
        else if($(this).attr('id') == 'id_empName' && $(this).val() == ""){
            $(this).hide();
            $("#id_empNameTip").show();
        }
        else if($(this).attr('id') == 'id_empPwd' && $(this).val() == ""){
            $(this).hide();
            $("#id_empPwdTip").show();
        }
    });
    //user login
    init_login(false,'id_username','id_password','id_login','login-form','/accounts/login/','../../data/index/','id_fp_identify')
    checkDriver(true);

    //employee login
    init_login(false,'id_empName','id_empPwd','id_empLogin','emp-login-form','/selfservice/login/','/selfservice/index/','emp_id_fp_identify')
});